package com.hsj;

public class StatePattern {
    public static void main(String[] args) {
        Context context = new Context();
        for (int i = 0; i <= 100; i++) {
            Expre expre = Factory1.createExpre(i);
            context.changeState(expre);
            context.transef();
        }
    }
}


abstract class Factory1 {
    public static Expre createExpre(int i) {
        if (i==0){
            return new D();
        }else if (i %3 ==0 & i % 5 ==0){
            return new AB();
        }else if(i%3 ==0 & i%7==0){
            return new AC();
        }else if (i%5 ==0 & i%7 ==0){
            return new BC();
        }else if (i % 3 == 0 ) {
            return new A();
        } else if (i % 5 == 0) {
            return new B();
        } else if (i % 7 == 0) {
            return new C();
        } else {
            return new D();
        }
    }
}


abstract class Expre {  //抽象一个状态
    abstract void sys();
}

class AB extends Expre {

    @Override
    void sys() {
        System.out.println("AB");
    }
}
class BC extends Expre {

    @Override
    void sys() {
        System.out.println("AB");
    }
}

class AC extends Expre {

    @Override
    void sys() {
        System.out.println("AC");
    }
}
class A extends Expre {

    @Override
    void sys() {
        System.out.println("A");
    }
}

class B extends Expre {

    @Override
    void sys() {
        System.out.println("B");
    }
}

class C extends Expre {
    @Override
    void sys() {
        System.out.println("C");
    }
}

class D extends Expre {
    @Override
    void sys() {
        System.out.println("other");
    }
}


class Context {
    private Expre state;

    public void changeState(Expre state) {
        this.state = state;
    }

    public void transef() {
        state.sys();
    }
}
